<?php
class config {
    private $filename = "config/config.ini";
    private $config;
    public  $section;
    public  $value;

    public function getConfig() {
        if($this->getConfigFile()) {
            if(isset($this->section)) {
                $section = $this->getSection();
                if(isset($this->value)) {
                    $value = $this->getValue($section);
                    return $value;
                }
                return $section;
            }
            else {
                return $this->config;
            }
        }
    }
    
    private function getConfigFile() {
        try {
            if(!file_exists($this->filename)) {
                throw new Exception("Cannot find config file");
            }
            if(!$this->config = @parse_ini_file($this->filename, 1)) {
                throw new Exception("Cannot parse config file");
            }
            return true;
        }
        catch(Exception $e) {
            throw new customException($e);
        }
    }
    
    private function getSection() {
        try {
            if(!array_key_exists($this->section, $this->config)) {
                throw new Exception("Cannot find section in config");
            }
            return $this->config[$this->section];
        }
        catch(Exception $e) {
            throw new customException($e);
        }
    }
    
    private function getValue($section) {
        try {
            if(!array_key_exists($this->value, $section)) {
                throw new Exception("Cannot find value in config section");
            }
            return $section[$this->value];
        }
        catch(Exception $e) {
            throw new customException($e);
        }
    }
}
?>